<?php
namespace Badmins\Model;
use Think\Model;
class ModelModel extends Model{
	protected $_validate = array(
			array('name','require','模型名称必须'),
	);
	protected $_auto = array (
		array('attr_ids','sortattrid',3,'callback',1),
		array('spec_ids','sortspecid',3,'callback',1),
	);
	/**
	 * 属性
	 * @return string
	 */
	public function sortattrid(){
		$attr_id = I('attr_ids');
		if(!empty($attr_id)){
			$attrsort = I('attr_sort');
			arsort($attrsort);
			foreach ($attrsort as $i=>$va){
				$newattr_id[] = $attr_id[$i];
			}
			return join(",",$newattr_id);
		}else{
			return "";
		}
	}
	/**
	 * 规格
	 * @return string
	 */
	public function sortspecid(){
		$spec_id = I('spec_ids');
		if(!empty($spec_id)){
			$specsort = I('spec_sort');
			arsort($specsort);
			foreach ($specsort as $k=>$vaa){
				$newspec_id[] = $spec_id[$k];
			}
			return join(",",$newspec_id);
		}else{
			return "";
		}
	}
}